package jvm.gc;

import java.util.concurrent.locks.LockSupport;

/*
* 测试system.gc()
* */
public class Test1 {
    public static void main(String[] args) {
        new Test1();
        System.gc();//提醒jvm进行垃圾回收 但是不保证马上执行
//        LockSupport.park();

    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        System.out.println("finalize...");
    }
    public void unpark(Thread thread){
           LockSupport.unpark(thread);
    }
}
class Test2{
    public static void main(String[] args) {
          localvarGC5();
    }
    public static void localvarGC1(){
           byte[]buffer=new byte[1024*1024*10];//10MB
           System.gc();
    }
    public static void localvarGC2(){
        byte[]buffer=new byte[1024*1024*10];//10MB
        buffer=null;
        System.gc();
    }
    public static void localvarGC3(){//14M->12M(14M)
        {//代码块
            byte[]buffer=new byte[1024*1024*10];//10MB
        }
        System.gc();
    }
    public static void localvarGC4(){//14M->1M(14M)
        {//代码块
            byte[]buffer=new byte[1024*1024*10];//10MB
        }
        int val=10;
        System.gc();
    }
    public static void localvarGC5(){//14M->1M(14M)
        localvarGC1();
        System.gc();
    }
}
